/*
 * Main.fx
 *
 * Created on Apr 9, 2010, 2:00:25 PM
 */

package slideshow;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;

import javafx.scene.paint.Color;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.animation.Timeline;
import javafx.animation.KeyFrame;
import javafx.animation.transition.FadeTransition;
import javafx.animation.Interpolator;
import javafx.ext.swing.*;
/**
 * @author Chris Tum
 */


def images = for(i in [1..12]){ Image {url: "{__DIR__}pic{i}.jpg"};}
def imageView = ImageView {image: bind currImg};
var currImg = images[0];

def fade = FadeTransition{
    duration: .5s
    node: imageView
    fromValue: 1.0
    toValue: 0.1
    repeatCount: 2
    autoReverse: true
}

Timeline {
	repeatCount: Timeline.INDEFINITE
	keyFrames: [at(0s){currImg => images[0]},
                    KeyFrame{time: 4.5s action:function(){fade.play();}}
                    at(5s){currImg => images[1]},
                    KeyFrame{time: 9.5s action:function(){fade.play();}}
                    at(10s){currImg => images[2]},
                    KeyFrame{time: 14.5s action:function(){fade.play();}}
                    at(15s){currImg => images[3]},
                    KeyFrame{time: 19.5s action:function(){fade.play();}}
                    at(20s){currImg => images[4]},
                    KeyFrame{time: 24.5s action:function(){fade.play();}}
                    at(25s){currImg => images[5]},
                    KeyFrame{time: 29.5s action:function(){fade.play();}}
                    at(30s){currImg => images[6]},
                    KeyFrame{time: 34.5s action:function(){fade.play();}}
                    at(35s){currImg => images[7]},
                    KeyFrame{time: 39.5s action:function(){fade.play();}}
                    at(40s){currImg => images[8]},
                    KeyFrame{time: 44.5s action:function(){fade.play();}}
                    at(45s){currImg => images[9]},
                    KeyFrame{time: 49.5s action:function(){fade.play();}}
                    at(50s){currImg => images[10]},
                    KeyFrame{time: 54.5s action:function(){fade.play();}}
                    at(55s){currImg => images[11]},
                    KeyFrame{time: 59.5s action:function(){fade.play();}}
                    at(60s){currImg => images[12]},
                    KeyFrame{time: 64.5s action:function(){fade.play();}}
                    at(65s){currImg=> images[0]}
                    ]
}.play();


var windowStage:Stage = Stage{

   onClose:function()
   {
       FX.exit()
   }//end onClose()

   title: "JavaFX Slideshow"
   width: 500
   height: 500
   scene: Scene {
      width: 600
      height: 600
      fill: Color.BLACK;
      content: [imageView , SwingButton{
                                 translateX:0
                                 translateY:0
                                 text: "Toggle Fullscreen"
                                 action: function()
                                 {
                                     if(windowStage.visible)
                                     {
                                         toggleFullscreen(fullscreenStage, windowStage)

                                     }
                                     else
                                     {
                                         toggleFullscreen(windowStage, fullscreenStage)
                                     }
                       
                                 }
      }]
   }
   visible:true
}
/////////////////////////////////////////////////////////////////////////////////
var fullscreenStage = Stage
{
    fullScreen: true
    visible: false
}
//button that intialte the toggle check to see which stage is visible
function toggleFullscreen(toVis:Stage, toNotVis:Stage)
{
    toNotVis.visible = false;
    toVis.scene = toNotVis.scene;
    toNotVis.scene = null;
    toVis.visible = true;
}
